﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Data;

namespace PracticeProject
{
    public partial class ActViewForm : Form
    {
        Activity act;
        Goal relatedGoal;

        public ActViewForm(Activity activity)
        {
            InitializeComponent();
            act = activity;
            relatedGoal = act.GetParentGoal();
            SetView();
            lblGoal.Click += new EventHandler(lblGoal_Click);
        }

        void SetView()
        {
            lblDesc.Text = act.Description;
            lblBegDate.Text = act.StartingTime.ToString();
            lblEndDate.Text = act.ExpectedEndingTime.ToString();
            lblRealTime.Text = act.RealEndingTime == new DateTime() ? "Not done" : act.RealEndingTime.ToString();
            textBox1.Text = act.Comments;
            if (relatedGoal!=null)
            {
                lblGoal.Text = relatedGoal.Description;
                lblGoal.Enabled = true;
                
            }
            else
            {
                lblGoal.Text = "none";
                lblGoal.Enabled = false;
                
            }
            if (act.RelatedGoalId == 0)
                menuDetach.Enabled = false;
            else
                menuDetach.Enabled = true;
        }

        void lblGoal_Click(object sender, EventArgs e)
        {
            GoalViewForm f = new GoalViewForm(relatedGoal);
            f.ShowDialog();
            SetView();
        }

        private void menuItem4_Click(object sender, EventArgs e)
        {

        }

        private void menuItem5_Click(object sender, EventArgs e)
        {

        }

        private void menuItem6_Click(object sender, EventArgs e)
        {

        }

        private void label7_ParentChanged(object sender, EventArgs e)
        {

        }

        private void menuItem5_Click_1(object sender, EventArgs e)
        {
            Adding_Activity_Form f = new Adding_Activity_Form(act);
            f.ShowDialog();
            act = f.activ;
            
            SetView();
        }

        private void menuItem2_Click(object sender, EventArgs e)
        {
            ElementCollection elements = ElementCollection.OpenCollectionFromXml();
            SelectParen f = new SelectParen(act.RelatedGoalId);
            f.ShowDialog();
            act.RelatedGoalId = f.ParentGoalId;
            relatedGoal = act.GetParentGoal();
            elements.EditActivity(act);
            elements.SaveCollectionToXml();
            SetView();
        }

        private void menuSetToDone_Click(object sender, EventArgs e)
        {
            SetingToDoneActivity f = new SetingToDoneActivity();
            if (f.ShowToSetDate(act))
            {

                ElementCollection elements = ElementCollection.OpenCollectionFromXml();

                elements.EditActivity(act);
                elements.SaveCollectionToXml();
                SetView();
            }
        }

        private void menuItem6_Click_1(object sender, EventArgs e)
        {
            ElementCollection elements = ElementCollection.OpenCollectionFromXml();
            elements.DeleteActivity(act);
            elements.SaveCollectionToXml();
            Close();
        }

        private void menuItem3_Click(object sender, EventArgs e)
        {
            ElementCollection elements = ElementCollection.OpenCollectionFromXml();
            act.RelatedGoalId = 0;
            relatedGoal = null;
            elements.EditActivity(act);
            elements.SaveCollectionToXml();
            SetView();
        }
    }
}